<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\heepay\controller;

class AdminMember extends \app\AdminRest
{
    protected $model;
    protected $rights_model;
    protected $config_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\heepay\model\Member();
        $this->config_model = new \app\heepay\model\Config();
    }
    public function configInfo()
    {
        $config_model = new \app\heepay\model\Config();
        $dis = ["uniacid" => $this->_uniacid];
        $data = $config_model->dataInfo($dis);
        return $this->success($data);
    }
    public function configUpdate()
    {
        $input = $this->_input;
        $config_model = new \app\heepay\model\Config();
        $dis = ["uniacid" => $this->_uniacid];
        $data = $config_model->dataUpdate($dis, $input);
        return $this->success($data);
    }
    public function memberList()
    {
        $input = $this->_param;
        $dis[] = ["a.status", ">", -1];
        $dis[] = ["a.uniacid", "=", $this->_uniacid];
        $where = [];
        if(!empty($input["name"])) {
            $where[] = ["a.bank_account_name", "like", "%" . $input["name"] . "%"];
            $where[] = ["a.apply_no", "like", "%" . $input["name"] . "%"];
        }
        $data = $this->model->adminList($dis, $input["limit"], $where);
        return $this->success($data);
    }
    public function memberAdd()
    {
        $heepay_model = new \longbingcore\heepay\HeePay($this->_uniacid);
        $input = $this->_input;
        $find = $this->model->where(["user_id" => $input["user_id"]])->where("status", ">", -1)->find();
        if(!empty($find)) {
            $this->errorMsg("该用户已有账户");
        }
        $list = $input["list"];
        unset($input["list"]);
        $list["if_sign"] = 1;
        $res = $heepay_model->addUser($list);
        if($res["code"] != 10000) {
            $this->errorMsg($res["sub_msg"]);
        }
        $input = array_merge($input, $list);
        $input["uniacid"] = $this->_uniacid;
        $input["apply_no"] = $res["biz_content"]["apply_no"];
        $this->model->dataAdd($input);
        return $this->success(true, 200);
    }
    public function memberUpdate()
    {
        $heepay_model = new \longbingcore\heepay\HeePay($this->_uniacid);
        $input = $this->_input;
        $data = $this->model->dataInfo(["id" => $input["id"]]);
        $find = $this->model->where(["user_id" => $data["user_id"]])->where("id", "<>", $input["id"])->where("status", ">", -1)->find();
        if(!empty($find)) {
            $this->errorMsg("该用户已有账户");
        }
        $list = $input["list"];
        $list["apply_no"] = $data["apply_no"];
        unset($input["list"]);
        $list["if_sign"] = 1;
        $res = $heepay_model->updateUser($list);
        if($res["code"] != 10000) {
            $this->errorMsg($res["sub_msg"]);
        }
        $input = array_merge($input, $list);
        $input["audit_status"] = 0;
        $this->model->dataUpdate(["id" => $input["id"]], $input);
        return $this->success(true, 200);
    }
    public function memberStatusUpdate()
    {
        $input = $this->_input;
        $this->model->dataUpdate(["id" => $input["id"]], ["status" => $input["status"]]);
        return $this->success(true);
    }
    public function memberInfo()
    {
        $input = $this->_param;
        $data = $this->model->dataInfo(["id" => $input["id"]]);
        $user_model = new \app\massage\model\User();
        $data["nickName"] = $user_model->where(["id" => $data["user_id"]])->value("nickName");
        return $this->success($data);
    }
    public function fileAdd()
    {
        $input = $this->_input;
        $heepay_model = new \longbingcore\heepay\HeePay($this->_uniacid);
        $input["file"] = FILE_UPLOAD_PATH . $input["file"];
        $res = $heepay_model->fileUpdate($input["file"], $input["type"]);
        if($res["code"] != 10000) {
            $this->errorMsg($res["sub_msg"]);
        }
        return $this->success($res);
    }
    public function adminHeepay()
    {
        $admin_model = new \app\massage\model\Admin();
        $user_id = $admin_model->where(["id" => $this->_user["id"]])->value("user_id");
        $data = $this->model->where(["user_id" => $user_id])->where("status", ">", -1)->find();
        return $this->success($data);
    }
}

?>